<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE html>
<head>
    <meta charset="UTF-8">
    <title>合生元</title>
    <script>
        var phoneWidth = parseInt(window.screen.width);
        var phoneHeight = parseInt(window.screen.height);
        var phoneScale = phoneWidth / 640;
        var ua = navigator.userAgent;
        if (/Android (\d+\.\d+)/.test(ua)) {
            var version = parseFloat(RegExp.$1);
            if (version > 2.3) {
                document.write('<meta name="viewport" content="width=640, initial-scale= ' + phoneScale + ' ,minimum-scale = ' + phoneScale + ', maximum-scale = ' + phoneScale + ', target-densitydpi=device-dpi">');
            }
            else {
                document.write('<meta name="viewport" content="width=640, initial-scale= ' + phoneScale + ' , target-densitydpi=device-dpi">');
            }
        }
        else {
            document.write('<meta name="viewport" content="width=640, user-scalable=no, target-densitydpi=device-dpi">');
        }</script>
    <link rel="stylesheet" href="../assets/css/draw/main2.css"/>
    <script type="text/javascript">
	function onBridgeReady(){
		WeixinJSBridge.call('hideOptionMenu');
	}
	
	if (typeof WeixinJSBridge == "undefined"){
	if( document.addEventListener ){
			document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
		}else if (document.attachEvent){
			document.attachEvent('WeixinJSBridgeReady', onBridgeReady); 
			document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
		}
	}else{
		onBridgeReady();
	}
	</script>            
</head>
<body>
<div class="wrap share2-bj">
    <h2 class="share-title"></h2>
    <i class="share-arrow"></i>
    		
			<c:forEach items="${gridList}" var="grid" varStatus="status">
				<c:choose>
				   <c:when test="${grid.isExists== 0 && grid.sort== 0}">  
    					<a href="javascript:;" class="samll-bird one-bird" id='${grid.id}' ></a>
				   </c:when>
				   <c:when test="${grid.isExists== 0 && grid.sort== 1}">  
    					<a href="javascript:;" class="samll-bird two-bird"id='${grid.id}' ></a>
				   </c:when>		
				   <c:when test="${grid.isExists== 0 && grid.sort== 2}">  
    					<a href="javascript:;" class="samll-bird three-bird" id='${grid.id}' ></a>
				   </c:when>	
				   <c:when test="${grid.isExists== 0 && grid.sort== 3}" >  
    					<a href="javascript:;" class="samll-bird four-bird" id='${grid.id}' ></a>
				   </c:when>						   					   		   
				</c:choose>							 					 
			</c:forEach>			   
    
    <!--中奖弹窗start-->
    <div class="Popup1-box Popup1-box-bj">
        <div class="light"></div>
        <div class="xx-content">
            <i class="small-xx small-xx-left"></i>
            <span class="large-xx"></span>
            <i class="small-xx small-xx-right"></i>
        </div>
        <div class="Frame">
             <a href="${root}/f/shareIndex?shareId=${shareId}&openId=${openid}&fromSystem=${fromSystem}" class="Frame-clear" id="Frame-clear1"></a>
            <span class="winning-title"></span>
            <h2><span class="winning-name">法国机票</span></h2>
            <h3>
                <p id="description">填写领奖信息吧</p>
                <span class="winning-name2">法国机票</span>
            </h3>
            <a href="#" class="Frame-btn">填写领奖信息</a>
        </div>
        <a href="javascript:;" class="Popup-bird1"></a>
    </div>
    <!--中奖弹窗end-->
    <!--未中奖弹窗start-->
    <div class="Popup2-box Popup2-box-bj" >
        <div class="xx-content2">
            <i class="small-xx2 small-xx-left2"></i>
            <span class="large-xx2"></span>
            <i class="small-xx2 small-xx-right2"></i>
        </div>
        <div class="Frame2">
            <a href="${root}/f/shareIndex?shareId=${shareId}&openId=${openid}&fromSystem=${fromSystem}" class="Frame-clear"></a>
            <span class="no-winning-title"></span>
            <h3>

            </h3>
            <a href="${root}/f/shareIndex?shareId=${shareId}&openId=${openid}&fromSystem=${fromSystem}" class="Frame-btn2">返回</a>
        </div>
        <a href="javascript:;" class="Popup-bird2"></a>
    </div>
    <!--未中奖弹窗 end-->
    <!--来晚了，奖品被抽完了，start-->
    <div class="Popup3-box Popup3-box-bj">

        <div class="Frame2">
            <a href="${root}/f/shareIndex?shareId=${shareId}&openId=${openid}&fromSystem=${fromSystem}" class="Frame-clear"></a>
            <h2 class="share2-text"></h2>
            <a href="${root}/f/shareIndex?shareId=${shareId}&openId=${openid}&fromSystem=${fromSystem}" class="Frame-btn2">确定</a>
        </div>
        <a href="javascript:;" class="Popup-bird2 Popup-bird3"></a>
    </div>
    <!--来晚了，奖品被抽完了 end-->
    <!--您已经抽过奖了，start-->
    <div class="Popup4-box Popup4-box-bj">
        <div class="Frame2">
            <a href="${root}/f/shareIndex?shareId=${shareId}&openId=${openid}&fromSystem=${fromSystem}" class="Frame-clear"></a>
            <h2 class="share2-text2"></h2>
            <a href="${root}/f/shareIndex?shareId=${shareId}&openId=${openid}&fromSystem=${fromSystem}" class="Frame-btn2">确定</a>
        </div>
        <a href="javascript:;" class="Popup-bird2 Popup-bird3"></a>
    </div>
    <!--您已经抽过奖了 end-->    
    
  <!--来晚了，该分享已过期，start-->
    <div class="Popup5-box Popup5-box-bj">
        <div class="Frame2">
            <a href="javascript:;" class="Frame-clear"></a>
            <h2 class="share2-text3"></h2>
            <a href="javascript:;" class="Frame-btn2">确定</a>
        </div>
        <a href="javascript:;" class="Popup-bird2 Popup-bird3"></a>
    </div>
    <!--来晚了，该分享已过期 end-->    
</div>

<!--js-->
<script src="http://wximg.qq.com/wxp/libs/wxmoment/0.0.4/wxmoment.min.js"></script>
   <script type="text/javascript">
	function onBridgeReady(){
		WeixinJSBridge.call('hideOptionMenu');
	}
	
	if (typeof WeixinJSBridge == "undefined"){
	if( document.addEventListener ){
			document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
		}else if (document.attachEvent){
			document.attachEvent('WeixinJSBridgeReady', onBridgeReady); 
			document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
		}
	}else{
		onBridgeReady();
	}
</script>    
<script>

/**弹框方法**/
function tip(msg){
	
	//弹框
	alert(msg);
	
	 			
}

$(function(){
	var expire = '${expire}';
	if(expire == '1'){
		alert("该分享已过期");
		$('.Popup5-box-bj').show();		
	}
});

$(".samll-bird").on("click", function (o) {
	$(".samll-bird").unbind("click");
	var gridId = $(this).attr("id");
	var shareId = ${shareId};
	var openid = '${openId}'; 
	var fromSystem = '${fromSystem}';
	
		//异步请求抽奖
		$.ajax({
			url:'${ctxFront}/shareDraw',
			type:'post',
			data:{ openid : openid , shareId : shareId , gridId : gridId,fromSystem: fromSystem},
			dataType:'json',
			success:function(res){
				flag = false;
				if(!res || !res.error){
					alert('抽奖异常:请求响应格式不正确');
					return;
				}
				
				if(res.error.errCode==1){
					if(res.error.errMsg != null){
						return;
					}else{
						alert("注册成为合生元会员即有机会抽取千元大奖");
						return;
					}
				}
				
				//抽奖正常
				var awardDto = res.obj;
				if(awardDto != null){
					if(!awardDto.check){
						
						//$('.Popup4-box-bj').show();//来晚了，奖品被抽完了
						if(awardDto.msg == '不好意思，每人只能抽一次！'){							
							$('.Popup4-box-bj').show();
						} 
						
						if(awardDto.msg == '不好意思，该奖品已被抽走！'){
							$('.Popup2-box-bj').show();
						}											
						
						if(awardDto.msg == '调用积分或者优惠券接口失败'){
							$('.Popup2-box-bj').show();
						}							
						
						else if(awardDto.msg == '不好意思，奖品已被抽完！'){
							$('.Popup3-box-bj').show();
						}
											
						return
					}
					
					if(awardDto.award){
						   $("#"+gridId).html("×")		

 						   if(awardDto.awardId == '0'){
							   $(".Popup2-box").show();
						   }else{
							   $(".Popup1-box").show();
						   }	 
						   
						   $(".Popup1-box").show();
						   
							var awardTypeName = awardDto.awardtypeName;
														
								//奖品名称
							var name =$("#awardname");
								
							//修改奖品信息
							$(".winning-name").html(awardDto.awardName);	
							$(".winning-name2").html(awardDto.awardName);	
							
							//提示信息
							var tipsHtml = null;   							
							$(".winning-name2").hide();	
							
							//非会员  
							if(awardDto.ifMember == false){														
				                //跳到分享页面
								tipsHtml = "领取有效期为1个小时";				                
				                $('.Frame-btn').html('填写手机号领取');	
						        $('.Frame-btn').attr('href',awardDto.registerUrl); 
				                $('#Frame-clear1').hide();
							}
							
							//会员
							else{
								
								if(awardTypeName  ==  'moviecode'){
									tipsHtml = "马上跟好友组队看电影吧";			
								}else{
									tipsHtml = "详情请到合生元账户查看";		
								}									
				                $('.Frame-btn').html('确定');
								$('.Frame-btn').attr('href','${ctxFront}/shareIndex?shareId='+shareId+'&openId='+openid); 
							}
							
							$("#description").html(tipsHtml);	

					}else{
						$(".Popup2-box").show()
						alert(awardDto.msg);
						return;
					}
				}else{
					alert('抽奖异常:抽奖返回数据错误');
					return;
				}
				
			},
			error:function(res){
				if(res.responseText != null){
					alert('抽奖异常:'+res.responseText);
					return;
				}else{
					alert("网络加载延迟,请再试!");
					return;
				}    					  					
			}
			
		})      	 	
	
});
</script>
</body>
</html>